new Vue({
  el: '#app',
  data() {
    return {
      pickerOptionsTwo,//时间选择器，范围选择
      form: {
        Launch_Time_1:'',//
        Launch_Time_2:'',//
        End_Time_1:'',
        End_Time_2:'',
        End_State:'',
        Approval_Record_SerialNumber:'',
        Founder:'',
        UserNumber:$.cookie('use'),
        Enterprise_Info_SerialNumber:$.cookie('enterprise'),
        page: 1,			//页数
        limit: 10,			//每页数据条数
      },
      Start_Date: null,//根据时间筛选
      End_Date:null,//结束时间
      total: 0,
      tableData: [],		//表格数据
    }
  },
  mounted() {
      this.getList(this.form)
  },
  computed:{//计算属性
      Status(){
          return function (str) {
              try {
                  if (str == '1') {return '审批中'}
                  else if(str == '2') { return '已通过'}
                  else if(str == '3') { return '已驳回' }
                  else if(str == '') { return '已撤销' }
                  else { return str }
              } catch (error) {
                  return str
              }
          }
      }
  },
  methods: {
    onSerach() {				//查询方法
      if (this.Start_Date) {
          this.form.Launch_Time_1 = this.Start_Date[0]
          this.form.Launch_Time_2 = this.Start_Date[1]
      } else {
          this.form.Launch_Time_1 = ''
          this.form.Launch_Time_2 = ''
      }
      if (this.End_Date) {
          this.form.End_Time_1 = this.End_Date[0]
          this.form.End_Time_2 = this.End_Date[1]
      } else {
          this.form.End_Time_1 = ''
          this.form.End_Time_2 = ''
      }
      this.form.page = 1;
      this.getList(this.form)
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList(this.form)
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form)
    },
    getList(data) {     //换页方法
      let _this = this
      $.ajax({
        type: 'POST',
        url: `${DomainName}/getPendingApprovalAction?token=${$.cookie('token')}`,
        data,
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        success: function (Result) {
          console.log(Result);
          if(Result.Status=='success'){
            _this.tableData = Result.tableData
            _this.total = parseInt(Result.limit)
          }
        },
        dataType: "json"
      });
    },
    onExcel() {
      var wb = XLSX.utils.table_to_book(document.querySelector("#out-table"));
      var wbout = XLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array"
      });
      try {
        //  name+'.xlsx'表示导出的excel表格名字
        saveAs(
          new Blob([wbout], {
            type: "application/octet-stream"
          }),
          "审批记录" + ".xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    },
    Show(row){
      sessionStorage.setItem("flow_id", row.Approval_Record_SerialNumber)
      sessionStorage.setItem("onApproval_record_detail_id", row.Approval_Record_Detail_SerialNumber)
      window.location.href = './show.html'
    },
    Delete(row) {
      const _this = this
      this.$confirm('该审批所有记录将被删除，且不可恢复，确认删除？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        $.ajax({
          url: DomainName + '/DeleteAction?token=' +$.cookie('token'),
          type: 'POST',
          data:{
            TableName:'function_approval_config',
            Primary_Key:row.Function_Approval_SerialNumber,
            Primary_Key_Name:'Function_Approval_SerialNumber',
            Row_Status:row.Row_Status == '0'?'1':'0',
            Operation_Name:row.Row_Status=='0'?'停用功能':'恢复功能'
          },
          success: function (res) {
            if (res.Status == 'success') {
              _this.getList(_this.form);
              _this.$message({
                type: 'success',
                message: row.Row_Status=='0'?'停用成功!':'恢复成功!'
              });
            }
          },
          complete: function (XMLHttpRequest) {
            if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
              window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
            }
          }
        })
      }).catch(() => {
        this.$message({
          type: 'warning',
          message: '已取消操作'
        });
      });
    },
  },
})